#include<iostream>
using namespace std;
class BaseAccount {
protected:
	string name;
	string account;
	int balance;
public:
	BaseAccount(){}
	BaseAccount(string n,string a,int b):name(n),account(a),balance(b){}
	void deposit(int m) {
		balance += m;
	}
	virtual void withdraw(int m) {
		if (balance < m) {
			cout << "insufficient" << endl;
		}
		else {
			balance -= m;
		}
	}
	virtual void display() {
		cout << name << ' ' << account << " Balance:" << balance << endl;
	}
};
class BasePlus :public BaseAccount {
protected:
	int limit;
	int num;
public:
	BasePlus() {
		limit = 5000;
	}
	BasePlus(string n, string a, int b) :BaseAccount(n, a, b) {
		limit = 5000;
		num = 0;
	}
	virtual void withdraw(int m) {
		if (balance + limit - num < m) {
			cout << "insufficient" << endl;
		}
		else {
			if (m <= balance) {
				balance -= m;
			}
			else {
				m -= balance;
				balance = 0;
				num += m;
			}
		}
	}
	virtual void display() {
		cout << name << ' ' << account << " Balance:" << balance << " limit:" << limit - num << endl;
	}
};
int main()
{
	int t;
	cin >> t;
	string name;
	string account;
	int balance;
	int d1, w1, d2, w2;
	BaseAccount* pv;
	for (int i = 0; i < t; i++) {
		cin >> name >> account >> balance >> d1 >> w1 >> d2 >> w2;
		if (account[1]=='A') {
			BaseAccount BA(name, account, balance);
			pv = &BA;
			pv->deposit(d1);
			pv->withdraw(w1);
			pv->deposit(d2);
			pv->withdraw(w2);
			pv->display();
		}
		else {
			BasePlus BP(name, account, balance);
			pv = &BP;
			pv->deposit(d1);
			pv->withdraw(w1);
			pv->deposit(d2);
			pv->withdraw(w2);
			pv->display();
		}
	}
	return 0;
}